<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/include/header.jsp" %>
<%-- 커뮤니티 정보 변경을 할수 있는 페이지 --%>
<div width="980px">
<table border="0" cellpadding="0" cellspacing="0" width="980px">
	<tr>
		<td style="vertical-align: top;width: 180px;background-color: #fdb73a;">
			<%@ include file="adminmenu.jsp"%>
		</td>
		<td style="text-align: center;vertical-align: top;width: 800px;">
		<%-- 커뮤니티 정보를 먼저 보여준다 --%>
			<table style="width: 800px;" cellpadding="0" cellspacing="0">
				<tr>
						<html:form action="/communityinfo" enctype="multipart/form-data">
						<input type="hidden" name="method" value="receiveInfo"/>
					<td style="vertical-align: top;">
					<div style="height: 10px;"></div>
						<table style="width: 500px;text-align: left;border: 1px solid #999999;" cellpadding="0" cellspacing="0">
						  <tr>
							<td colspan="2" style="height: 40px;background: #000000;"><img src="<%=imagePath %>commadmin_info_02.jpg" border="0"/></td>
							<html:hidden property="cono"/>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_05.jpg" border="0"/></td>
							<td style="width: 400px;height: 20px;"><bean:write name="communityForm" property="coname"/></td>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 60px;"><img src="<%=imagePath %>commadmin_info_07.jpg" border="0"/></td>
							<td><html:textarea property="coguide" style="height: 60px;width: 390px;"/></td>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_08.jpg" border="0"/></td>
							<td>					
								<html:select property="ccno" style="height: 20px;widows: 400px;font-size: 8pt;">
									<html:optionsCollection property="categorys" value="ccno" label="ccname"/>
								</html:select>
							</td>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_09.jpg" border="0"/></td>
							<td>
								<html:select property="coopen" style="height: 20px;widows: 400px;font-size: 8pt;">
									<html:option value="2">공개</html:option>
									<html:option value="3">비공개</html:option>
								</html:select>
							</td>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 80px;"><img src="<%=imagePath %>commadmin_info_10.jpg" border="0"/></td>
							<td style="vertical-align: top;"><html:file property="file" onchange="changeFile(this.value)"  style="height: 20px;width: 400px;font-size: 8pt;"/><br/>
								<html:hidden property="cologosfn"/>
								<logic:notEmpty name="communityForm" property="cologosfn">
									<img id="photo" src="<%=path%>/uploadfiles/<bean:write name="communityForm" property="cologosfn"/>" style="border: 1px solid #999999;width: 390px;height: 40px;"/>
								</logic:notEmpty>
								<logic:empty name="communityForm" property="cologosfn">
									<img id="photo" src="" style="display: none;width: 390px;height: 40px;"/>
								</logic:empty>
							</td>							
						  </tr>
						  <tr>
							<td colspan="2" style="height: 20px;"><img src="<%=imagePath %>commadmin_info_11.jpg" border="0"/></td>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 60px;"><img src="<%=imagePath %>commadmin_info_12.jpg" border="0"/></td>
							<td><html:textarea property="copoptext" style="height: 60px;width: 390px;"/></td>
						  </tr>
						  <tr>
							<td style="width: 100px;height: 20px;"><img src="<%=imagePath %>commadmin_info_14.jpg" border="0"/></td>
							<td style="height: 20px;">높이 : <html:text property="copopheight" styleClass="commPopupSize" onkeypress="numbercheck()"/>&nbsp;&nbsp;&nbsp;&nbsp;
							넓이 : <html:text property="copopwidth" styleClass="commPopupSize" onkeypress="numbercheck()"/></td>
						  </tr>
						  </table>
						<div style="height: 10px;"></div>
						<%int count=1; %>
						<table id="tableObj" style="width: 500px; border: 1px solid #999999;" cellpadding="0" cellspacing="0"> 
							<tr>
								<td colspan="3" style="height: 40px;background: #000000;"><img src="<%=imagePath %>commadmin_info_15.jpg" border="0"/></td>
							</tr>
							<tr>
								<td style="width: 200px;height: 20px;"><img src="<%=imagePath %>commadmin_info_16.jpg" border="0"/></td>
								<td colspan="2" style="width: 300px;height: 20px;text-align: left;"><img src="<%=imagePath %>commadmin_info_17.jpg" border="0"/></td>
							</tr>
							<logic:notEmpty name="communityForm" property="communityLinks">
								<logic:iterate id="cls" name="communityForm" property="communityLinks" type="model.CommunityLink">
									<tr>
										<input type="hidden" name="linkno<%=count%>" value="<bean:write name="cls" property="linkno"/>">								
										<td style="width: 200px;height: 20px;">
											<input type="text" name="linkname<%=count%>" value="<bean:write name="cls" property="linkname"/>" class="commLinkSize" style="width: 190px;"/></td>
										<td style="width: 250px;height: 20px;">
											<input type="text" name="linkaddress<%=count++%>" value="<bean:write name="cls" property="linkaddress"/>" class="commLinkSize" style="width: 240px;"/></td>
										<td style="width: 200px;height: 20px;">
											<img src="<%=imagePath %>commadmin_info_18.jpg" border="0"  onclick="linkdelete('<bean:write name="cls" property="linkno"/>')" onmouseover="this.style.cursor = 'hand'"/></td>										
									</tr>
								</logic:iterate>
								<input type="hidden" name="linkcount" id="lc" value=<%=--count%>>
								<input type="hidden" name="isLink" value="true">
							</logic:notEmpty>
							<logic:empty name="communityForm" property="communityLinks">
								<tr>
									<td style="width: 200px;height: 20px;"><input type="text" name="linkname<%=count%>" class="commLinkSize" style="width: 190px;"/></td>
									<td style="width: 250px;height: 20px;"><input type="text" name="linkaddress<%=count%>" class="commLinkSize" style="width: 240px;"/></td>
								</tr>
								<input type="hidden" name="linkcount" id="lc" value=<%=count%>>
								<input type="hidden" name="isLink" value="false">
							</logic:empty>
							<input type="hidden" name="linkcount2" id="lc" value=<%=count%>>	
							
						</table>
					<div style="width: 500px;height: 40px;text-align: center;padding-top: 10px;">							
							<img src="<%=imagePath %>commadmin_info_20.jpg" border="0" onClick="javascript:addItem()" onmouseover="this.style.cursor = 'hand'"/>
							<img src="<%=imagePath %>commadmin_info_21.jpg" border="0" onClick="javascript:removeItem('<bean:write name="communityForm" property="linksize"/>')" onmouseover="this.style.cursor = 'hand'"/>
					</div>
					<div style="width: 500px;height: 40px;text-align: right;">
						<img id="sbbutton" src="<%=imagePath %>commadmin_info_23.jpg" border="0" onclick="javascript:formcheck()" onmouseover="this.style.cursor = 'hand'"/>
						<img src="<%=imagePath %>commadmin_info_24.jpg" border="0" onclick="javascript:history.go(-1)" onmouseover="this.style.cursor = 'hand'"/>
					</div>
					</td>
						</html:form>
					<td style="height: 500px;width: 200px;"><img src="<%=imagePath %>commadmin_info_04.jpg" border="0"/>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<script type="text/javascript">
	<%-- 파일의 확장자를 구하는 메소드 --%>
	function getFileExtension(filePath){
	    var lastIndex = -1;
	    lastIndex = filePath.lastIndexOf('.');
	    var extension = "";
	
		if(lastIndex != -1){
		    extension = filePath.substring(lastIndex + 1, filePath.len);
		}else{
		    extension = "";
		}
		return extension;
	}

	<%-- 그림파일인지 아니지를 체크하는 메소드 --%>
	function changeFile(filesrc){	
		var check = getFileExtension(filesrc);
		
	     if(!((check.toLowerCase()=="jpg") || (check.toLowerCase()=="jpeg") || (check.toLowerCase()=="gif"))){
	        document.getElementById("sbbutton").disabled = true;
	        alert("jpg, jpeg, gif 파일만 올려주세요~!");
	        return;
	    }
	    
	    document.getElementById("sbbutton").disabled = false;
	    
	    var img = new Image();
		img.src = filesrc;
		if(img.fileSize > 500*1024){
	    	alert('500kb가 넘어 갑니다.');
	    	return false;
	    }
		document.getElementById('photo').style.display="";
		document.getElementById('photo').src=filesrc;	
	}
	
	<%-- 링크추가 버튼을 눌렀을시 새로운 칸 생성 --%>
	function addItem(){ 
            var rows  = tableObj.rows.length;
            var linkcount = document.getElementById('lc');
		  	linkcount.value = parseInt(linkcount.value)+1;
		  	
            newTr=tableObj.insertRow(rows);
            
            _td = document.createElement('<TD>')
            _td.style.width = "250";
  	 		newTd=newTr.insertCell(_td);
  	 		var addressadd = '<input type="text" name="linkaddress'+linkcount.value+'" class="commLinkSize" style="width: 240px;"/>';
	  	 	newTd.insertAdjacentHTML('afterBegin',addressadd);
	  	 	
            _td = document.createElement('<TD>')
            _td.style.width = "200";
  	 		newTd=newTr.insertCell(_td);
		 	var nameadd = '<input type="text" name="linkname'+linkcount.value+'" class="commLinkSize" style="width: 190px;"/>';
		  	newTd.insertAdjacentHTML('afterBegin',nameadd);

    }
    
    
    <%-- 링크 삭제를 눌렀을대 해당하는 메소드 --%>
    function removeItem(linksize){
		var rows  = parseInt(tableObj.rows.length);
		linksize = parseInt(linksize);
		if(rows>2+linksize){
			tableObj.deleteRow(rows-1);
			var linkcount = document.getElementById('lc');
			linkcount.value = parseInt(linkcount.value)-1;
		}else{
			alert('저장된 링크를 삭제할 때는 delete를 눌러주세요');
		}
	}
    
    <%-- 링크를 Delete 버튼을 눌렀을때 발생하는 메소드 --%>
    function linkdelete(linkno){
		location.href = "<%=path%>/community/communityinfo.do?method=linkdelete&linkno="+linkno+"&cono=<%=request.getParameter("cono")%>";		
	}
	
	<%-- 숫자 검사 --%>
	function numbercheck(){
		if((event.keyCode<48)||(event.keyCode>57)){
			alert('숫자만 가능합니다.');
			event.returnValue=false;		
		}
	}
	
	<%-- 전송 시 전체적으로 항목들을 체크 --%>
	function formcheck(){
		var coguide = document.communityForm.coguide.value;
		var recoguide = coguide.replace(/\s/g,'');

		if(recoguide.length<30){
			alert('커뮤니티 설명은 공백 제외 30자 이상입니다.');
			return false;
		}
		
		var linkcount = parseInt(document.getElementById('lc').value);
		for(var i=1;i<linkcount+1;i++){
			var link1 = "linkname"+i;
			var link2 = "linkaddress"+i;
			var linkname = document.getElementById(link1).value;
			var linkaddress = document.getElementById(link2).value;
			var relinkname = linkname.replace(/\s/g,'');
			var relinkaddress = linkaddress.replace(/\s/g,'');
			
			if(relinkname.length>0){
				if(relinkaddress.length<1){
					alert('링크주소를 입력해주세요');
					return false;
				}
			}
			
			if(relinkaddress.length>0){
				if(relinkname.length<1){
					alert('링크명을 입력해주세요');
					return false;
				}
				var sublink = relinkaddress.substr(0,7);
				if(sublink != "http://"){
					document.getElementById(link2).value='http://'+linkaddress;
				}
			}				
		}
		
		var width = document.getElementById('copopwidth').value;
		var height = document.getElementById('copopheight').value;
		if(width>500 || height >500){
			alert('500*500 이 최대입니다.');
			return false;
		}
		
		
		communityForm.submit();
	}
</script>
</div>
<%@ include file="../common/include/footer.jsp" %>